home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / d_menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  7.0 KB  |  327 lines

  1. /*
  2.  * Routines for the dialing directory menu.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <curses.h>
  7. #include "config.h"
  8. #include "dial_dir.h"
  9. #include "misc.h"
  10. #include "param.h"
  11.  
  12. static int current = 1;
  13. /*
  14.  * Display the dialing directory and prompt for options.  A non-zero return
  15.  * code means we're ready to dial.
  16.  */
  17.  
  18. int
  19. dial_menu()
  20. {
  21.     extern int xmc;
  22.     WINDOW *dm_win, *newwin();
  23.     char buf[5], ld_code;
  24.     int ans, start, needs_repair, count, x, y, i, ret_code;
  25.     void print_dir(), st_line();
  26.     static void dir_scroll(), active_ld(), disp_ld();
  27.  
  28.     touchwin(stdscr);
  29.     refresh();
  30.     st_line("");
  31.  
  32.     dm_win = newwin(22, 78, 1, 1);
  33.     mvwattrstr(dm_win, 1, 20, A_BOLD, "D I A L I N G       D I R E C T O R Y");
  34.     horizontal(dm_win, 2, 0, 78);
  35.     mvwattrstr(dm_win, 3, 0, A_STANDOUT, "           Name                   Number        Baud P D S Dpx  Script/TTY    ");
  36.                     /* show 10 entries */
  37.     dir_scroll(dm_win, current);
  38.  
  39.     mvwaddstr(dm_win, 15, 4, "==>");
  40.     mvwattrch(dm_win, 15, 14, A_BOLD, 'R');
  41.     waddstr(dm_win, " Revise");
  42.     mvwattrch(dm_win, 15, 34, A_BOLD, 'M');
  43.     waddstr(dm_win, " Manual Dialing");
  44.     mvwaddstr(dm_win, 15, 55, "Entry to Dial");
  45.  
  46.     mvwattrch(dm_win, 16, 14, A_BOLD, 'P');
  47.     waddstr(dm_win, " LD Codes");
  48.     mvwattrch(dm_win, 16, 34, A_BOLD, 'D');
  49.     waddstr(dm_win, " Delete Entry");
  50.     mvwattrstr(dm_win, 16, 55, A_BOLD, "<CR>");
  51.     waddstr(dm_win, " Scroll Down");
  52.  
  53. #ifdef OLDCURSES
  54.     mvwattrstr(dm_win, 17, 14, A_BOLD, "U/N");
  55. #else /* OLDCURSES */
  56.     mvwattrstr(dm_win, 17, 14, A_BOLD, "<up>/<down>");
  57. #endif /* OLDCURSES */
  58.     waddstr(dm_win, " Page");
  59.     mvwattrch(dm_win, 17, 34, A_BOLD, 'L');
  60.     waddstr(dm_win, " Print Entries");
  61.     mvwattrstr(dm_win, 17, 55, A_BOLD, "<ESC>");
  62.     waddstr(dm_win, " Exit");
  63.  
  64.     mvwaddstr(dm_win, 19, 4, "LD Codes Active:");
  65.                     /* show which LD codes are active */
  66.     active_ld(dm_win);
  67.  
  68.     box(dm_win, VERT, HORZ);
  69.     y = 15;
  70.     x = 8;
  71.     wmove(dm_win, 15, 8);
  72.     wrefresh(dm_win);
  73.  
  74. #ifndef OLDCURSES
  75.     keypad(dm_win, TRUE);
  76. #endif /* OLDCURSES */
  77.                     /* prompt for options */
  78.     count = 0;
  79.     ld_code = '\0';
  80.     ret_code = 0;
  81.     do {
  82.         needs_repair = 0;
  83.         ans = wgetch(dm_win);
  84.                     /* get an entry number */
  85.         if (ans >= '0' && ans <= '9') {
  86.             if (count > 2) {
  87.                 beep();
  88.                 continue;
  89.             }
  90.             buf[count] = ans;
  91.             waddch(dm_win, (chtype) ans);
  92.             wrefresh(dm_win);
  93.             count++;
  94.             continue;
  95.         }
  96.         switch (ans) {
  97.             case DEL:
  98.             case BS:    /* do our own backspace */
  99.                 if (!count) {
  100.                     beep();
  101.                     break;
  102.                 }
  103.                 count--;
  104.                 if (!count)
  105.                     ld_code = '\0';
  106.                 buf[count] = '\0';
  107.                 getyx(dm_win, y, x);
  108.                 x--;
  109.                 wmove(dm_win, y, x);
  110.                 waddch(dm_win, (chtype) ' ');
  111.                 wmove(dm_win, y, x);
  112.                 wrefresh(dm_win);
  113.                 break;
  114. #ifndef OLDCURSES
  115.             case KEY_UP:
  116. #endif /* OLDCURSES */
  117.             case 'u':
  118.             case 'U':    /* up arrow key */
  119.                 if (current == 1) {
  120.                     beep();
  121.                     break;
  122.                 }
  123.                 start = current - 10;
  124.                 if (start < 1)
  125.                     start = 1;
  126.                 current = start;
  127.                 dir_scroll(dm_win, start);
  128.                 break;
  129. #ifndef OLDCURSES
  130.             case KEY_DOWN:
  131.             case '\n':
  132. #endif /* OLDCURSES */
  133.             case 'n':
  134.             case 'N':    /* down arrow key */
  135.                 if (current == NUM_DIR-9) {
  136.                     beep();
  137.                     break;
  138.                 }
  139.                 start = current + 10;
  140.                 if (start > NUM_DIR-9)
  141.                     start = NUM_DIR-9;
  142.                 current = start;
  143.                 dir_scroll(dm_win, start);
  144.                 break;
  145.             case '\r':    /* <CR> key */
  146.                 if (!count) {
  147.                     if (current == NUM_DIR-9) {
  148.                         beep();
  149.                         break;
  150.                     }
  151.                     current++;
  152.                     if (current > NUM_DIR-9)
  153.                         current = NUM_DIR-9;
  154.                     dir_scroll(dm_win, current);
  155.                 }
  156.                 /*
  157.                  * The <CR> is used for the scroll-down-one-line
  158.                  * function, and to terminate numeric input.
  159.                  */
  160.                 else {
  161.                     buf[count] = '\0';
  162.                     i = atoi(buf);
  163.                     if (!i || i > NUM_DIR) {
  164.                         beep();
  165.                         mvwaddstr(dm_win, 15, 8, "   ");
  166.                         x = 8;
  167.                         count = 0;
  168.                         break;
  169.                     }
  170.                     dir->q_ld[0] = ld_code;
  171.                     dir->q_num[0] = i;
  172.                     dir->d_cur = i;
  173.  
  174.                     /* end of queue marker */
  175.                     dir->q_num[1] = -1;
  176.  
  177.                     ret_code++;
  178.                     break;
  179.                 }
  180.                 break;
  181.             case 'r':
  182.             case 'R':    /* revise */
  183.                 if (revise()) {
  184.                     active_ld(dm_win);
  185.                     dir_scroll(dm_win, current);
  186.                 }
  187.                 touchwin(dm_win);
  188.                 break;
  189.             case 'p':    /* display LD codes */
  190.             case 'P':
  191.                 disp_ld();
  192.                 touchwin(dm_win);
  193.                 needs_repair++;
  194.                 break;
  195.             case 'd':
  196.             case 'D':    /* delete a range of entries */
  197.                 if (delete())
  198.                     dir_scroll(dm_win, current);
  199.                 touchwin(dm_win);
  200.                 break;
  201.             case 'm':
  202.             case 'M':    /* manual dial */
  203.                 if (manual()) {
  204.                     ret_code++;
  205.                     break;
  206.                 }
  207.                 touchwin(dm_win);
  208.                 needs_repair++;
  209.                 break;
  210.             case 'l':
  211.             case 'L':    /* print the entries */
  212.                 print_dir();
  213.                 touchwin(dm_win);
  214.                 needs_repair++;
  215.                 break;
  216.             case '+':    /* LD codes */
  217.             case '-':
  218.             case '@':
  219.             case '#':
  220.                 waddch(dm_win, (chtype) ans);
  221.                 wrefresh(dm_win);
  222.                 ld_code = ans;
  223.                 continue;
  224.             case ESC:    /* <ESC> key (exit) */
  225.             case 4:
  226.                 break;
  227.             default:
  228.                 beep();
  229.         }
  230.         if (ret_code)
  231.             break;
  232.                     /* magic cookie terminal? */
  233.         if (xmc > 0 && needs_repair) {
  234.             clear_line(dm_win, 1, 0, FALSE);
  235.             clear_line(dm_win, 3, 0, FALSE);
  236.             wrefresh(dm_win);
  237.             mvwattrstr(dm_win, 1, 20, A_BOLD, "D I A L I N G       D I R E C T O R Y");
  238.             mvwattrstr(dm_win, 3, 0, A_STANDOUT, "           Name                   Number        Baud P D S Dpx  Script/TTY    ");
  239.             box(dm_win, VERT, HORZ);
  240.         }
  241.         wmove(dm_win, y, x);
  242.         wrefresh(dm_win);
  243.     } while (ans != ESC);
  244.  
  245.     werase(dm_win);
  246.     wrefresh(dm_win);
  247.     delwin(dm_win);
  248.     if (ret_code) {
  249.         touchwin(stdscr);
  250.         refresh();
  251.     }
  252.     return(ret_code);
  253. }
  254.  
  255. /*
  256.  * Scroll the dialing directory.  Actually, we're not doing a real scroll
  257.  * function on the screen, we're just repainting 10 lines.
  258.  */
  259.  
  260. static void
  261. dir_scroll(win, start)
  262. WINDOW *win;
  263. int start;
  264. {
  265.     int i;
  266.  
  267.     wmove(win, 4, 0);
  268.     for (i=start; i<start+10; i++)
  269.         wprintw(win,
  270.          "%4d- %-20.20s %18.18s  %5d-%c-%d-%d  %c  %-14.14s\n", i,
  271.          dir->name[i], dir->number[i], dir->baud[i], dir->parity[i],
  272.          dir->dbits[i], dir->sbits[i], dir->duplex[i], dir->script[i]);
  273.     box(win, VERT, HORZ);
  274.     return;
  275. }
  276.  
  277. /*
  278.  * Display the Long Distance codes.  Press any key to continue.
  279.  */
  280.  
  281. static void
  282. disp_ld()
  283. {
  284.     WINDOW *ld_win, *newwin();
  285.  
  286.     ld_win = newwin(12, 30, 0, 0);
  287.     mvwaddstr(ld_win, 1, 5, "Long Distance Codes\n");
  288.     horizontal(ld_win, 2, 0, 30);
  289.     mvwprintw(ld_win, 3, 2, "+ %-20.20s", param->ld_plus);
  290.     mvwprintw(ld_win, 5, 2, "- %-20.20s", param->ld_minus);
  291.     mvwprintw(ld_win, 7, 2, "@ %-20.20s", param->ld_at);
  292.     mvwprintw(ld_win, 9, 2, "# %-20.20s", param->ld_pound);
  293.     box(ld_win, VERT, HORZ);
  294.  
  295.     mvwaddstr(ld_win, 11, 8, " Press any key ");
  296.     wmove(ld_win, 11, 29);
  297.     wrefresh(ld_win);
  298.     wgetch(ld_win);
  299.                     /* it overlaps, so erase it */
  300.     werase(ld_win);
  301.     wrefresh(ld_win);
  302.     delwin(ld_win);
  303.     return;
  304. }
  305.  
  306. /*
  307.  * Display which of the Long Distance codes are active.
  308.  */
  309.  
  310. static void
  311. active_ld(win)
  312. WINDOW *win;
  313. {
  314.     mvwaddstr(win, 19, 21, "        ");
  315.     wmove(win, 19, 21);
  316.                     /* a NULL means it's not active */
  317.     if (*param->ld_plus != '\0')
  318.         waddstr(win, "+ ");
  319.     if (*param->ld_minus != '\0')
  320.         waddstr(win, "- ");
  321.     if (*param->ld_at != '\0')
  322.         waddstr(win, "@ ");
  323.     if (*param->ld_pound != '\0')
  324.         waddstr(win, "# ");
  325.     return;
  326. }
  327.